//
//  EFHomeMessageView.m
//  EnjogFood
//
//  Created by 王芳 on 17/7/14.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFHomeMessageView.h"

@interface EFHomeMessageView ()
@property (strong, nonatomic) UIView *backView;
@property (strong, nonatomic) UIView *backSolidView;
@property (strong, nonatomic) UIImageView *backImageV;
@property (strong, nonatomic) UIImageView *bellImageV;
@property (strong, nonatomic) UILabel *contentLabel;
@property (strong, nonatomic) UIButton *knowBtn;
@end

@implementation EFHomeMessageView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame withContent:(NSString *)content{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.backView];
        [self addSubview:self.backSolidView];
        
        [self.backSolidView addSubview:self.backImageV];
        self.backImageV.top = (kScreenHeight - self.backImageV.height)/2;
        self.backImageV.left = (kScreenWidth - self.backImageV.width)/2;
        [self.backImageV addSubview:self.bellImageV];
        [self.backImageV addSubview:self.contentLabel];
        [self.backImageV addSubview:self.knowBtn];
        
        
        self.bellImageV.top = -33;
        self.bellImageV.centerX = self.backImageV.width/2;
        self.contentLabel.top = self.bellImageV.bottom + 6;
        self.contentLabel.left = 27;
        self.contentLabel.text = content;
        [self.contentLabel sizeToFit];
        self.contentLabel.width = 197;
        
        self.knowBtn.centerX = self.backImageV.width/2;
        self.knowBtn.bottom = self.backImageV.height - 10;
    }
    return self;
}

- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _backView.backgroundColor = RGBCOLOR(0x000000);
        _backView.alpha = 0.6;
    }
    return _backView;
}

- (UIView *)backSolidView{
    if (!_backSolidView) {
        _backSolidView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        _backSolidView.backgroundColor = [UIColor clearColor];
    }
    return _backSolidView;
}

- (UIImageView *)backImageV{
    if (!_backImageV) {
        _backImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250, 209)];
        _backImageV.image = IMG(@"buttonsmall_bg_default");
        _backImageV.userInteractionEnabled = YES;
    }
    return _backImageV;
}

- (UIImageView *)bellImageV{
    if (!_bellImageV) {
        _bellImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 66, 66)];
        _bellImageV.image = IMG(@"Group");
    }
    return _bellImageV;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.textColor = RGBCOLOR(0x666666);
        _contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.numberOfLines = 0;
    }
    return _contentLabel;
}

- (UIButton *)knowBtn{
    if (!_knowBtn) {
        _knowBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 17)];
        [_knowBtn setTitle:@"我知道了" forState:UIControlStateNormal];
        [_knowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_knowBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _knowBtn;
}

- (void)btnClick{
    [self removeFromSuperview];
}

@end
